
#include <ros/ros.h>
#include "customize_topic/Person.h"

//这个回调函数的参数为ConstPtr智能指针
void chatter_callback(const customize_topic::Person::ConstPtr &msg)
{
    ROS_INFO("收到: %s, %d, %f", msg->name.c_str(), msg->age, msg->height);
}


int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "listener_person");

    ros::NodeHandle nh;

    ros::Subscriber chatter_sub = nh.subscribe<customize_topic::Person>("chatter_person", 100, chatter_callback);
    //订阅消息回调处理函数，spin函数会陷入死循环，没有消息时会阻塞也不占用CPU资源
    ros::spin();
    return 0;
}